import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/",
    component: Layout,
    redirect: "/order",
    component: () => import("@/views/order/index"),
  },
  // {
  //   path: "/login",
  //   component: () => import("@/views/login/index"),
  // },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },
  {
    path: "/order",
    component: Layout,
    redirect: "/order",
    meta: { title: "出车管理", icon: "iconfont el-icon-huoche" },
    children: [
      {
        path: "/project",
        name: "project",
        component: () => import("@/views/order/project"),
        meta: { title: "项目详情" },
      },
      {
        path: "/order",
        name: "Order",
        component: () => import("@/views/order/index"),
        meta: { title: "出车登记" },
      },
    ],
  },
  {
    path: "/financial",
    component: Layout,
    redirect: "/financial",
    meta: { title: "财务管理", icon: "iconfont el-icon-caiwu-xianxing" },
    children: [
      // {
      //   path: "/account",
      //   name: "Account",
      //   component: () => import("@/views/financial/account/index"),
      //   meta: { title: "出车记录", icon: "el-icon-s-marketing" },
      // },
      {
        path: "/money",
        name: "Money",
        component: () => import("@/views/financial/money/index"),
        meta: { title: "收付款" },
      },
      {
        path: "/income",
        name: "income",
        component: () => import("@/views/financial/income/index"),
        meta: { title: "收付款明细" },
      },
      {
        path: "/invoice",
        name: "Invoice",
        component: () => import("@/views/financial/invoice/index"),
        meta: { title: "发票登记明细" },
      },
      {
        path: "/Transaction",
        name: "Transaction",
        component: () => import("@/views/financial/transaction/index"),
        meta: { title: "签证单" },
      },

      {
        path: "/balance",
        name: "Balance",
        component: () => import("@/views/financial/balance/index"),
        meta: { title: "账户统计" },
      },
    ],
  },
  {
    path: "/accessories",
    component: Layout,
    redirect: "/accessories",
    meta: { title: "配件管理", icon: "iconfont el-icon-kucunguanli" },
    children: [
      {
        path: "/inventory",
        name: "inventory",
        component: () => import("@/views/accessories/inventory"),
        meta: { title: "库存明细" },
      },
      {
        path: "/details",
        name: "details",
        component: () => import("@/views/accessories/details"),
        meta: { title: "出库记录" },
      },
    ],
  },
  {
    path: "/personnel",
    component: Layout,
    redirect: "/personnel",
    meta: { title: "员工管理", icon: "iconfont el-icon-yuangong" },
    children: [
      {
        path: "/employees",
        name: "Employees",
        component: () => import("@/views/personnel/employees/index"),
        meta: { title: "员工列表" },
      },
      // {
      //   path: "/wages",
      //   name: "wages",
      //   component: () => import("@/views/personnel/wages/index"),
      //   meta: { title: "工资统计" },
      // },
      // {
      //   path: "/OA",
      //   name: "OA",
      //   component: () => import("@/views/personnel/OA/index"),
      //   meta: { title: "加班/奖金" },
      // },
    ],
  },
  {
    path: "/car",
    component: Layout,
    redirect: "/car",
    children: [
      {
        path: "/car",
        name: "Car",
        component: () => import("@/views/car/index"),
        meta: {
          title: "车辆管理",
          icon: "iconfont el-icon-cheliangyanshigongju",
        },
      },
    ],
  },
  {
    path: "/suppliers",
    component: Layout,
    redirect: "/suppliers",
    children: [
      {
        path: "/suppliers",
        name: "Suppliers",
        component: () => import("@/views/suppliers/index"),
        meta: {
          title: "供应商信息",
          icon: "iconfont el-icon-gongyingshangguanli",
        },
      },
    ],
  },
  {
    path: "/customers",
    component: Layout,
    redirect: "/customers",
    children: [
      {
        path: "/customers",
        name: "Customers",
        component: () => import("@/views/customers/index"),
        meta: { title: "客户信息", icon: "iconfont el-icon-kehu" },
      },
    ],
  },
  {
    path: "/company",
    component: Layout,
    redirect: "/company",
    children: [
      {
        path: "/company",
        name: "Company",
        component: () => import("@/views/company/index"),
        meta: { title: "公司信息", icon: "iconfont el-icon-gongsixinxi" },
      },
    ],
  },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
